﻿//using NetFwTypeLib;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

namespace Helpers
{
    public static class SysHelper
    {
        public static string AppGuid
        {
            get
            {
                try
                {
                    Assembly asm = Assembly.GetEntryAssembly();
                    object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
                    return new Guid((attr[0] as GuidAttribute).Value).ToString("B").ToUpper();
                }
                catch (Exception)
                {
                    return string.Empty;
                }
            }
        }

        ///// <summary>
        ///// 通过对象防火墙操作
        ///// </summary>
        ///// <param name="isOpenDomain">域网络防火墙（禁用：false；启用（默认）：true）</param>
        ///// <param name="isOpenPublicState">公共网络防火墙（禁用：false；启用（默认）：true）</param>
        ///// <param name="isOpenStandard">专用网络防火墙（禁用: false；启用（默认）：true）</param>
        ///// <returns></returns>
        //public static bool FirewallOperateByObject(bool isOpenDomain = true, bool isOpenPublicState = true, bool isOpenStandard = true)
        //{
        //    try
        //    {
        //        INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
        //        // 启用<高级安全Windows防火墙> - 专有配置文件的防火墙
        //        firewallPolicy.set_FirewallEnabled(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE, isOpenStandard);
        //        // 启用<高级安全Windows防火墙> - 公用配置文件的防火墙
        //        firewallPolicy.set_FirewallEnabled(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC, isOpenPublicState);
        //        // 启用<高级安全Windows防火墙> - 域配置文件的防火墙
        //        firewallPolicy.set_FirewallEnabled(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN, isOpenDomain);
        //    }
        //    catch (Exception e)
        //    {
        //        throw new Exception($"防火墙修改出错：{e.Message}");
        //    }
        //    return true;
        //}
    }
}
